<template>
  <el-dialog
    :title="!dataForm.id ? $t('Common.Add') : $t('Common.Edit')"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" :label-position="top" @keyup.enter.native="dataFormSubmit()">
    <el-form-item label="商家" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="商家"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="宾客进店计费分钟" prop="chargingMinutes">
      <el-input v-model="dataForm.chargingMinutes" placeholder="宾客进店计费分钟"></el-input>
    </el-form-item>
    <el-form-item label="进店时间在多少分钟之后的，算第二天退房" prop="afterPointNext">
      <el-input v-model="dataForm.afterPointNext" placeholder="进店时间在多少分钟之后的，算第二天退房"></el-input>
    </el-form-item>
    <el-form-item label="退房时间" prop="exitPoint">
      <el-input v-model="dataForm.exitPoint" placeholder="退房时间"></el-input>
    </el-form-item>
    <el-form-item label="超出时间计费规则(0按分钟1加收半天2不收房费)" prop="exceedType">
      <el-input v-model="dataForm.exceedType" placeholder="超出时间计费规则(0按分钟1加收半天2不收房费)"></el-input>
    </el-form-item>
    <el-form-item label="直到多少分钟加收全天房费" prop="nextTime">
      <el-input v-model="dataForm.nextTime" placeholder="直到多少分钟加收全天房费"></el-input>
    </el-form-item>
    <el-form-item label="超时后按多少分钟计费" prop="exceedMinutes">
      <el-input v-model="dataForm.exceedMinutes" placeholder="超时后按多少分钟计费"></el-input>
    </el-form-item>
    <el-form-item label="上个字段收取多少元" prop="exceedMoney">
      <el-input v-model="dataForm.exceedMoney" placeholder="上个字段收取多少元"></el-input>
    </el-form-item>
    <el-form-item label="不足按多少分钟超过多少分钟计费" prop="insufficientMinutes">
      <el-input v-model="dataForm.insufficientMinutes" placeholder="不足按多少分钟超过多少分钟计费"></el-input>
    </el-form-item>
    <el-form-item label="上个字段加收" prop="insufficientMoney">
      <el-input v-model="dataForm.insufficientMoney" placeholder="上个字段加收"></el-input>
    </el-form-item>
    <el-form-item label="超时宽限多少分钟" prop="timeoutGraceMinutes">
      <el-input v-model="dataForm.timeoutGraceMinutes" placeholder="超时宽限多少分钟"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          createTime: '',
          updateTime: '',
          chargingMinutes: '',
          afterPointNext: '',
          exitPoint: '',
          exceedType: '',
          nextTime: '',
          exceedMinutes: '',
          exceedMoney: '',
          insufficientMinutes: '',
          insufficientMoney: '',
          timeoutGraceMinutes: ''
        },
        dataRule: {
          sellerId: [
            { required: true, message: '商家不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          chargingMinutes: [
            { required: true, message: '宾客进店计费分钟不能为空', trigger: 'blur' }
          ],
          afterPointNext: [
            { required: true, message: '进店时间在多少分钟之后的，算第二天退房不能为空', trigger: 'blur' }
          ],
          exitPoint: [
            { required: true, message: '退房时间不能为空', trigger: 'blur' }
          ],
          exceedType: [
            { required: true, message: '超出时间计费规则(0按分钟1加收半天2不收房费)不能为空', trigger: 'blur' }
          ],
          nextTime: [
            { required: true, message: '直到多少分钟加收全天房费不能为空', trigger: 'blur' }
          ],
          exceedMinutes: [
            { required: true, message: '超时后按多少分钟计费不能为空', trigger: 'blur' }
          ],
          exceedMoney: [
            { required: true, message: '上个字段收取多少元不能为空', trigger: 'blur' }
          ],
          insufficientMinutes: [
            { required: true, message: '不足按多少分钟超过多少分钟计费不能为空', trigger: 'blur' }
          ],
          insufficientMoney: [
            { required: true, message: '上个字段加收不能为空', trigger: 'blur' }
          ],
          timeoutGraceMinutes: [
            { required: true, message: '超时宽限多少分钟不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomdayrule/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tHotelFloorRoomDayRule.sellerId
                this.dataForm.createTime = data.tHotelFloorRoomDayRule.createTime
                this.dataForm.updateTime = data.tHotelFloorRoomDayRule.updateTime
                this.dataForm.chargingMinutes = data.tHotelFloorRoomDayRule.chargingMinutes
                this.dataForm.afterPointNext = data.tHotelFloorRoomDayRule.afterPointNext
                this.dataForm.exitPoint = data.tHotelFloorRoomDayRule.exitPoint
                this.dataForm.exceedType = data.tHotelFloorRoomDayRule.exceedType
                this.dataForm.nextTime = data.tHotelFloorRoomDayRule.nextTime
                this.dataForm.exceedMinutes = data.tHotelFloorRoomDayRule.exceedMinutes
                this.dataForm.exceedMoney = data.tHotelFloorRoomDayRule.exceedMoney
                this.dataForm.insufficientMinutes = data.tHotelFloorRoomDayRule.insufficientMinutes
                this.dataForm.insufficientMoney = data.tHotelFloorRoomDayRule.insufficientMoney
                this.dataForm.timeoutGraceMinutes = data.tHotelFloorRoomDayRule.timeoutGraceMinutes
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomdayrule/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'chargingMinutes': this.dataForm.chargingMinutes,
                'afterPointNext': this.dataForm.afterPointNext,
                'exitPoint': this.dataForm.exitPoint,
                'exceedType': this.dataForm.exceedType,
                'nextTime': this.dataForm.nextTime,
                'exceedMinutes': this.dataForm.exceedMinutes,
                'exceedMoney': this.dataForm.exceedMoney,
                'insufficientMinutes': this.dataForm.insufficientMinutes,
                'insufficientMoney': this.dataForm.insufficientMoney,
                'timeoutGraceMinutes': this.dataForm.timeoutGraceMinutes
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: this.$t('Common.OperationSuccessful'),
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
